import React, {Component} from 'react'
import PropTypes from 'prop-types'
import FontAwesome from 'react-native-vector-icons/FontAwesome'
import MaterialIcons from 'react-native-vector-icons/MaterialIcons'
import Ionicons from 'react-native-vector-icons/Ionicons'
import Icon from 'react-native-vector-icons/Icon'
// import Icon from '../assets/iconFont/iconFont.js'

const iconMap = {
  FontAwesome: FontAwesome,
  MaterialIcons: MaterialIcons,
  Ionicons: Ionicons,
  MinaIcon: Icon
}
class MinaIcon extends Component {
  render() {
    const {name, size, style} = this.props
    if (!name.includes('|')) {
      throw new Error('name 解析错误！')
      return null
    }
    let nameArr = name.split('|')
    let fontlib = nameArr[0]
    let font = nameArr[1]
    let CustomIcon = iconMap[fontlib]
    if (!CustomIcon) throw new Error('没有找到匹配的font库，请review代码！')
    return (
      <CustomIcon name={font} size={size} style={style}/>
    )
  }
}

MinaIcon.propTypes = {
  name: PropTypes.string.isRequired,
  size: PropTypes.number.isRequired,
  style: PropTypes.object.isRequired
}

export default MinaIcon